package study.nosql.redis.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.eggs.result.Result;
import study.eggs.result.Results;

import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@RequestMapping("/key_event")
public class _8_KeyEventController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @RequestMapping("/set")
    public Result pub(@RequestBody String params) {
        redisTemplate.opsForValue().set("test", "ffffffffffff");
        redisTemplate.expire("test", 3, TimeUnit.SECONDS);

        return Results.ok();
    }
}
